package cn.edu.ujn.lab3.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.ujn.lab3.dao.BaseDict;
import cn.edu.ujn.lab3.dao.BaseDictMapper;
import cn.edu.ujn.lab3.service.BaseDictService;
import cn.edu.ujn.lab3.util.Page;


/**
 * 数据字典Service接口实现类
 */
@Service("baseDictService")
@Transactional
public class BaseDictServiceImpl implements BaseDictService{	
	@Autowired
	private BaseDictMapper baseDictDao;
	//根据类别代码查询数据字典
	public List<BaseDict> findBaseDictByTypeCode(String typecode) {
		return baseDictDao.selectBaseDictByTypeCode(typecode);
	}
	// 查询所有字典类目代码和类别名称并去重
	@Override
	public List<BaseDict> selectAllTypeCodeAndTypeName() {
		// TODO Auto-generated method stub
		return baseDictDao.selectAllTypeCodeAndTypeName();
	}
	// 列表
	@Override
	public Page<BaseDict> selectBaseDictList(Integer page, BaseDict baseDict) {
		baseDict.setStart((page-1)*baseDict.getRows());
		List<BaseDict> baseDictList = baseDictDao.selectBaseDictList(baseDict);
		Integer count = baseDictDao.selectBaseDictListCount(baseDict);
		System.out.println(count);
		Page<BaseDict> baseDictPage = new Page<BaseDict>();
		baseDictPage.setRows(baseDictList);
		baseDictPage.setPage(page);
		baseDictPage.setTotal(count);
		baseDictPage.setSize(baseDict.getRows());
		return baseDictPage;
	}
	//创建字典
	@Override
	public int createBaseDict(BaseDict baseDict) {
		
		return baseDictDao.insertSelective(baseDict);
	}
	//根据id查询字典
	@Override
	public BaseDict getBaseDictById(Integer id) {
		
		return baseDictDao.selectByPrimaryKey(String.valueOf(id));
	}
	//更新字典
	@Override
	public int updateBaseDict(BaseDict baseDict) {
		
		return baseDictDao.updateByPrimaryKey(baseDict);
	}
	//删除字典
	@Override
	public int deleteBaseDict(Integer id) {
		
		return baseDictDao.deleteByPrimaryKey(String.valueOf(id));
	}
}

